package com.baosight.xCyber.output;

import com.baosight.xCyber.config.OrderedProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.Map;
import java.util.Properties;


public class MapOutput {

    private static Logger logger = LoggerFactory.getLogger(MapOutput.class);

    public static void writeProperties(String propertiesFilePath, Map<String,String> data){

        Properties properties = new OrderedProperties();
        for (String key : data.keySet()) {
            properties.put(key, data.get(key));
            //properties.setProperty(key, data.get(key));
        }

        try {
            File file = new File(propertiesFilePath);
            if (!file.isFile()) {
                file.createNewFile();
            }
            OutputStream fos = new FileOutputStream(propertiesFilePath);
            properties.store(fos, null);
            fos.close();
            logger.info("data write to "+propertiesFilePath+" successful");
        } catch (FileNotFoundException e) {
            logger.info(propertiesFilePath+" cannot find:"+e.getMessage());
        }catch (IOException e) {
            logger.info("data write error:"+e.getMessage());
        }
    }
}
